package Offer;

/**
 * 数组中数字出现的次数 II
 * 一个数字出现一次，其他出现三次
 * @author 是阿秋啊
 * @date 2022/04/22 18:49
 **/
public class Num56II {
    public int singleNumber(int[] nums) {
        int[] counts = new int[32];
        for (int num : nums) {
            for (int i = 0; i < counts.length; i++) {
                counts[i] += num & 1;
                num >>>= 1;
            }
        }
        for (int i = 0; i < counts.length; i++) {
            counts[i] %=3;
        }
        int res = 0;
        for (int i = 0; i < counts.length; i++) {
            res <<= 1;
            res |= counts[31 - i];
        }
        return res;
    }
}
